
package com.zjff.myshop.admin.controller;

import cn.dev33.satoken.annotation.SaCheckRole;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.zjff.myshop.admin.pojo.form.OrderQueryPageForm;
import com.zjff.myshop.admin.pojo.vo.OrderVO;
import com.zjff.myshop.front.pojo.vo.OrderDetailVO;
import com.zjff.myshop.admin.service.OrderService;
import com.zjff.myshop.util.BeanUtils;
import com.zjff.myshop.util.PageList;
import com.zjff.myshop.util.PageQuery;
import com.zjff.myshop.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Map;

@CrossOrigin
@RestController
@Api(value = "v1", tags = "85.后台管理系统-订单模块")
@SaCheckRole("admin")   //需要admin角色
@RequestMapping("/admin/v1/order")
public class AdminOrderController {
    private static final Logger logger = LoggerFactory.getLogger(AdminOrderController.class);
    @Resource
    private OrderService orderService;

    /**
     * 查询订单分页列表
     */
    @ApiOperationSupport(order = 30)
    @ApiOperation(value = "查询订单列表", notes = "返回订单列表，接口参数：页码、页大小、状态、是否支付")
    @ApiImplicitParam(name = "form", value = "订单查询分页参数", dataType = "OrderQueryPageForm", required = true)
    @PostMapping("/queryPage")
    public Result<PageList<OrderVO>> queryPage(@Valid @RequestBody OrderQueryPageForm form) {
        //form参数有： page limit status
        Map<String, Object> map = BeanUtils.beanToMap(form);
        //参数中没有指定userId的值，表明是所有用户的。
        PageQuery pageQuery = new PageQuery(map); //封装分页请求参数
        PageList<OrderVO> pageList = orderService.selectPage(pageQuery);
        return Result.ok(pageList);
    }

    /**
     * 查询订单详情
     */
    @ApiOperationSupport(order = 31)
    @ApiOperation(value = "查询订单详情", notes = "返回订单id对应的订单详情")
    @ApiImplicitParam(name = "orderId", value = "订单id", required = true)
    @GetMapping("/{orderId}")
    public Result<OrderDetailVO> selectDetailById(@PathVariable("orderId") Integer orderId) {
        OrderDetailVO orderDetailVO = orderService.selectDetailById(orderId);
        return Result.ok(orderDetailVO);
    }
}